package org.apache.struts.ehr.medical_records.action;

import java.util.Map;

import org.apache.struts.ehr.medical_records.model.DischargePatient;
import org.apache.struts.ehr.medical_records.model.HL7Message;
import org.apache.struts.ehr.medical_records.model.ReplyMessage;

import com.earogya.communicate.Communicator;
import com.earogya.logic.medical_records.CreateADTA03;
import com.earogya.logic.medical_records.ParseReply;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class DischargePatientAction extends ActionSupport{

	private DischargePatient dischargePatient;
	private HL7Message message;
	private ReplyMessage replyMessage;
	
	public ReplyMessage getReplyMessage() {
		return replyMessage;
	}
	
	public DischargePatient getDischargePatient() {
		return dischargePatient;
	}

	public void setDischargePatient(DischargePatient dischargePatient) {
		this.dischargePatient = dischargePatient;
	}

	public HL7Message getMessage() {
		return message;
	}

	public String execute() throws Exception {
		Map<String, Object> session=ActionContext.getContext().getSession();
		replyMessage=new ReplyMessage();
		replyMessage.setMessage("empty");
		CreateADTA03 createMessage=new CreateADTA03(dischargePatient);
		String msg=createMessage.createMessage("CSTH");
		message=new HL7Message();
		if(!msg.equals(null)){
			Communicator c=new Communicator();
			String reply=c.sendMessage(msg);
			if(!reply.equals("No Reply")){
				ParseReply parse=new ParseReply();
				replyMessage=(ReplyMessage)parse.parseMessage(reply);
			}
		}
		else{
			message.setMessage("empty");
		}
		return SUCCESS;
	}
	
	public void validate(){
		
	}
	
}
